package ev;
import java.util.Random;

import TeamPursuit.*;

public class EA_Team_Women2 implements Team_Women {

	@Override
	public void emulation() {
		boolean [] strategy = {true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false};
	    int [] power = {400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400, 400};
    	SimulationResult result = null;
        WomensTeamPursuit womensTeamPursuit = new WomensTeamPursuit();
        
        int times = 100;
        double finalTime = 1000;
        Random r = new Random();
        boolean b;
        int index, pValue;
        boolean strategyValue;

		while(times>0){
			b=r.nextBoolean();
			//System.out.println("b= "+b);
			 if(b){		 
				 
				index = r.nextInt(power.length);
				pValue = power[index];
				power[index] = r.nextInt(1001)+200;
				//System.out.println(index+" "+power[index]);
	        	try {
	        		result = womensTeamPursuit.simulate(strategy, power);
				} catch (Exception e) {
					e.printStackTrace();
				}
				if(result.getProportionCompleted() < 0.9999998){
					//System.out.println(result.toString());
					power[index] = pValue;
					continue;
				}
				if(result.getFinishTime()<finalTime){
					finalTime = result.getFinishTime();
					//System.out.println(finalTime);
				}
				else{
					power[index] = pValue;
					//System.out.println(finalTime);
				}
			}else{
				index = r.nextInt(strategy.length);
				strategyValue = strategy[index];
				strategy[index] = !strategyValue;
				//System.out.println(index+" "+power[index]);
	        	try {
	        		result = womensTeamPursuit.simulate(strategy, power);
				} catch (Exception e) {
					e.printStackTrace();
				}
				if(result.getProportionCompleted() < 0.9999998){
					//System.out.println(result.toString());
					strategy[index] = strategyValue;
					continue;
				}
				if(result.getFinishTime()<finalTime){
					finalTime = result.getFinishTime();
					//System.out.println(finalTime);
				}else{
					strategy[index] = strategyValue;
					//System.out.println(finalTime);
				}
			}
			times--;
		}

		System.out.println("best= "+finalTime);
		System.out.println(result.toString());
	}

}